#pragma once
#include "OpenGl_Drawable.h"

class _GraphLayout;

class _Axis :
    public OpenGl_Drawable
{
    public:
        // Constructor / Destructor
        _Axis(_GraphLayout& Layout);
        ~_Axis(void);

        //// Drawing
        void setBaseSize(_u32 BaseSize);
        _u32 getBaseSize();

        // Visible
        void setVisible(bool Visible);
        bool isVisible();

        // Title Visible
        void setTitleVisible(bool Visible);
        bool isTitleVisible();

        // Color
        void setColor(COLORREF Color);
        COLORREF getColor();

        // Titlestring
        void setTitle(CStringW Title);
        CStringW& getTitle();

        // Rectangle of the control
        void setControlRect(CRect& Rect);

        // Min and max values on axis
        void setMinMax(double Min, double Max);

        // Get exponent
        _s32 getExponent(double Min, double Max);

        double getNiceMin()
        {
            return m_NiceMin;
        }

        double getNiceMax()
        {
            return m_NiceMax;
        }

        // Last Min/Max values to filter invalid values
        double m_LastMin;
        double m_LastMax;


    protected:

        // Renice the scale
        void NiceScale(double min, double max);
        void calculateTicks();
        double niceNum(double range, bool round);
        void setMaxTicks(unsigned int maxTicks1);

        // Precision
        unsigned int getPrecision(int Exponent);
        unsigned int m_MaxPrecision;

        // Convert coordinate
        double getScaledCoordinate(_u32 Tick);

        // Axis min/max
        double m_Min;               // Minimum value to be displayed
        double m_Max;               // Maximum value to be displayed
        double m_Range;             // Range inbetween min and max
        double m_TickSpacing;       // Tick spacing for range
        double m_NiceMin;           // Reniced Minimum
        double m_NiceMax;           // Reniced maximum
        _u32   m_MaxTicks;          // Maximum ticks on axis
        double m_FirstTickPosition; // Position of first tick

        // Other properties
        bool     m_Visible;       // Visibility
        _u32     m_BaseSize;      // Size
        COLORREF m_Color;         // Color
        CStringW m_Title;         // Titlestring
        bool     m_TitleVisible;  // Visibility of title
        _GraphLayout& m_Layout;   // Layout of the graph window
};


